// @ts-ignore
import { api } from '@/utils/api';

/** 登录 POST /security/login */
export async function securityLogin(
  body: string,
  options?: ArgumentsType<typeof api>[1]
): Promise<BASE.IResultString>;

export async function securityLogin(
  body: string,
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: true }
): Promise<TupleResponse<BASE.IResultString>>;

export async function securityLogin(
  body: string,
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: false }
): Promise<BASE.IResultString>;

export async function securityLogin(body: string, options?: ArgumentsType<typeof api>[1]) {
  if (
    (
      options as ArgumentsType<typeof api>[1] & {
        tupleResponse: boolean;
      }
    )?.tupleResponse === true
  ) {
    return api<BASE.IResultString>(`/app/security/login`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      data: body,
      ...(options || {}),
      tupleResponse: true
    });
  }

  return api<BASE.IResultString>(`/app/security/login`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: body,
    ...(options || {})
  });
}

/** 登出 POST /security/logout */
export async function securityLogout(
  options?: ArgumentsType<typeof api>[1]
): Promise<BASE.IResultString>;

export async function securityLogout(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: true }
): Promise<TupleResponse<BASE.IResultString>>;

export async function securityLogout(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: false }
): Promise<BASE.IResultString>;

export async function securityLogout(options?: ArgumentsType<typeof api>[1]) {
  if (
    (
      options as ArgumentsType<typeof api>[1] & {
        tupleResponse: boolean;
      }
    )?.tupleResponse === true
  ) {
    return api<BASE.IResultString>(`/app/security/logout`, {
      method: 'POST',
      ...(options || {}),
      tupleResponse: true
    });
  }

  return api<BASE.IResultString>(`/app/security/logout`, {
    method: 'POST',
    ...(options || {})
  });
}

/** 获取公钥 POST /security/publicKey */
export async function securityPublicKey(
  options?: ArgumentsType<typeof api>[1]
): Promise<BASE.IResultString>;

export async function securityPublicKey(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: true }
): Promise<TupleResponse<BASE.IResultString>>;

export async function securityPublicKey(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: false }
): Promise<BASE.IResultString>;

export async function securityPublicKey(options?: ArgumentsType<typeof api>[1]) {
  if (
    (
      options as ArgumentsType<typeof api>[1] & {
        tupleResponse: boolean;
      }
    )?.tupleResponse === true
  ) {
    return api<BASE.IResultString>(`/app/security/publicKey`, {
      method: 'POST',
      ...(options || {}),
      tupleResponse: true
    });
  }

  return api<BASE.IResultString>(`/app/security/publicKey`, {
    method: 'POST',
    ...(options || {})
  });
}

/** token续期 POST /security/renewal */
export async function securityRenewal(
  options?: ArgumentsType<typeof api>[1]
): Promise<BASE.IResultString>;

export async function securityRenewal(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: true }
): Promise<TupleResponse<BASE.IResultString>>;

export async function securityRenewal(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: false }
): Promise<BASE.IResultString>;

export async function securityRenewal(options?: ArgumentsType<typeof api>[1]) {
  if (
    (
      options as ArgumentsType<typeof api>[1] & {
        tupleResponse: boolean;
      }
    )?.tupleResponse === true
  ) {
    return api<BASE.IResultString>(`/app/security/renewal`, {
      method: 'POST',
      ...(options || {}),
      tupleResponse: true
    });
  }

  return api<BASE.IResultString>(`/app/security/renewal`, {
    method: 'POST',
    ...(options || {})
  });
}

/** 根据token获取用户信息 POST /security/self */
export async function securitySelf(
  options?: ArgumentsType<typeof api>[1]
): Promise<BASE.IResultIUser>;

export async function securitySelf(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: true }
): Promise<TupleResponse<BASE.IResultIUser>>;

export async function securitySelf(
  options?: ArgumentsType<typeof api>[1] & { tupleResponse: false }
): Promise<BASE.IResultIUser>;

export async function securitySelf(options?: ArgumentsType<typeof api>[1]) {
  if (
    (
      options as ArgumentsType<typeof api>[1] & {
        tupleResponse: boolean;
      }
    )?.tupleResponse === true
  ) {
    return api<BASE.IResultIUser>(`/app/security/self`, {
      method: 'POST',
      ...(options || {}),
      tupleResponse: true
    });
  }

  return api<BASE.IResultIUser>(`/app/security/self`, {
    method: 'POST',
    ...(options || {})
  });
}
